from sys import displayhook


class GradeManager:
    def __init__(self):
        self.students = []
        self.scores = []


    def add_student(self, name, score):
        """添加学生及其成绩"""
        if name in self.students:
            print(f"[警告{name}已存在!]")
        else:
            self.students.append(name)
            self.scores.append(score)
            print(f"成功添加: {name} - {score}分")


    def delete_student(self, name):
        """删除学生记录"""
        if name in self.students:
            index = self.students.index(name)
            self.students.pop(index)
            score = self.scores.pop(index)
            print(f"已删除: {name}(原成绩: {score}分)")
        else:
            print(f"[错误]找不到学生: {name}")

    def show_average(self):
        """计算并显示平均分"""


        if not self .scores:
            print("暂无成绩数据!")
        else:
            avg = sum(self.scores) / len(self.scores)
            print(f"当前平均分: {avg:.2f} (共{len(self.scores)}人)")
    def display_all(self):
        """显示所有学生成绩"""
        print("\n===== 成绩单=====")
        for name, score in zip(self.students, self.scores):
            print(f'{name}: {score}分')
        self.show_average()


manager = GradeManager()
manager.add_student("张三",85)
manager.add_student("李四",92)
manager.add_student("王五",78)


manager.display_all()
"""
==== 成绩单 ====
张三: 85分
李四: 92分
王五: 78分
当前平均分:85.00(共3人)
"""


manager.delete_student("李四")
manager.add_student("赵六",88)
manager.show_average()



original = [3, 2, 2, 1, 4]
unique = list(set(original))
print(unique)


unique = []
[unique.append(x) for x in original if x not in unique]
print(unique)


from collections import OrderedDict
unique = list(OrderedDict.fromkeys(original))
print(unique)



class AdvancedGradeManager(GradeManager):
    def remove_duplicates(self):
        """去除重复成绩的学生(保留第一个)"""
        seen = set()
        i = 0
        while i < len(self.students):
            if self.scores[i] in seen:
                print(f"移除重复成绩学生: {self.students[i]}(成绩:{self.scores[i]})")
                self.students.pop(i)
                self.scores.pop(i)
            else:
                seen.add(self.scores[i])
                i += 1



advanced_mgr = AdvancedGradeManager()
advanced_mgr.add_student("Alice", 90)
advanced_mgr.add_student("Bob", 85)
advanced_mgr.add_student("Charlie", 90)
advanced_mgr.add_student("David", 85)

advanced_mgr.remove_duplicates()
"""
移除重复成绩学生: Charlie(成绩: 90)
移除重复成绩学生: David(成绩: 85)
"""
advanced_mgr.display_all()
"""
==== 成绩单 ====
Alice: 90分
Bob: 85分
当前平均分: 87.50(共2人)
"""


